package com.luoye.lj.wstool.wsdm;

import com.luoye.lj.wstool.generator.ICodeGenerator;
import com.luoye.lj.wstool.web.entity.WebtEntity;
import com.luoye.lj.wstool.web.entity.WebtField;
import com.luoye.lj.wstool.wsdm.entity.WsdtEntity;
import com.luoye.lj.wstool.wsdm.entity.WsdtField;

/*
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 2016/7/7
 * Time: 15:45
 * To change this template use File | Settings | File Templates.
 */
public class HtmlDataCodeGenerator implements ICodeGenerator {
    private WsdtEntity wsdtEntity;

    public HtmlDataCodeGenerator(WsdtEntity wsdtEntity) {
        this.wsdtEntity = wsdtEntity;
    }

    @Override
    public String codeGenerate() {
        String code="";
        if(this.wsdtEntity!=null){
            if(this.wsdtEntity.getFieldList()!=null){
                for(WsdtField wsdtField:this.wsdtEntity.getFieldList()){
                    code+="            if(\\$(\"#"+wsdtField.getFieldName()+"\").val()!=\"\"){\n" +
                            "                data['"+wsdtField.getFieldName()+"']=\\$(\"#"+wsdtField.getFieldName()+"\").val();\n" +
                            "            }\n";
                    //code+="                "+webtField.getFieldName()+": \\$(\"#"+webtField.getFieldName()+"\").val(),\n";
                }
            }
        }
        return code;
    }
}
